package com.vne.skyemart.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
@Table(name = "permission", catalog = "skyemart_db")
@AssociationOverrides({
		@AssociationOverride(name = "pk.screen", joinColumns = @JoinColumn(name = "ScreenID")),
		@AssociationOverride(name = "pk.groups", joinColumns = @JoinColumn(name = "GroupID")) })
public class Permission implements Serializable{

	private static final long serialVersionUID = 3891224051033440385L;
	
	PermissionId pk = new PermissionId();
	
	@Column(name = "CreatedBy", nullable = false, length = 10)
	private int createdBy;
	
	@Temporal(TemporalType.DATE)
	@Column(name = "CreatedDate", nullable = false)
	private Date createdDate;
	
	@Column(name = "ModifiedBy", length = 10, nullable = true)
	private int modifiedBy;
	
	@Temporal(TemporalType.DATE)
	@Column(name = "ModifiedDate")
	private Date modifiedDate;
	
	@Column(name = "IsActived", length = 1)
	private String isActived;
	
	@EmbeddedId
	public PermissionId getPk() {
		return pk;
	}
	public void setPk(PermissionId pk) {
		this.pk = pk;
	}
	
	@Transient
	public Screen getScreen(){
		return getPk().getScreen();
	} 
	
	public void setScreen(Screen screen){
		getPk().setScreen(screen);
	}
	
	@Transient
	public Groups getGroups(){
		return getPk().getGroups();
	}
	
	public void setGroups(Groups groups){
		getPk().setGroups(groups);
	}
	
	public int getCreatedBy() {
		return createdBy;
	}
	public void setCreatedBy(int createdBy) {
		this.createdBy = createdBy;
	}
	public Date getCreatedDate() {
		return createdDate;
	}
	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}
	public int getModifiedBy() {
		return modifiedBy;
	}
	public void setModifiedBy(int modifiedBy) {
		this.modifiedBy = modifiedBy;
	}
	public Date getModifiedDate() {
		return modifiedDate;
	}
	public void setModifiedDate(Date modifiedDate) {
		this.modifiedDate = modifiedDate;
	}
	
	public String getIsActived() {
		return isActived;
	}
	public void setIsActived(String isActived) {
		this.isActived = isActived;
	}
	
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		Permission that = (Permission) o;

		if (getPk() != null ? !getPk().equals(that.getPk())
				: that.getPk() != null)
			return false;

		return true;
	}

	public int hashCode() {
		return (getPk() != null ? getPk().hashCode() : 0);
	}
	
	
}
